package com.aizuda.snailjob.controller;

import com.aizuda.snailjob.core.Collector;
import com.aizuda.snailjob.service.DataMigrationService;
import com.aizuda.snailjob.vo.MigrationVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class DataMigrationController {
    private final DataMigrationService dataMigrationService;

    @PostMapping("data-migration")
    public boolean migration(@RequestBody @Valid MigrationVO migrationVO) {
        try {
            dataMigrationService.migration(migrationVO);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @PostMapping("/migration/progress")
    public Collector migrationProgress() {
        return dataMigrationService.migrationProgress();
    }
}
